home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWInk.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  8.1 KB  |  283 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWInk.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #if defined(FW_PROFILER_CALLS) && defined(__MWERKS__)
  13. #pragma profile on
  14. #endif
  15.  
  16. #ifndef FWINK_H
  17. #include "FWInk.h"
  18. #endif
  19.  
  20. #ifndef FWGCONST_H
  21. #include "FWGConst.h"
  22. #endif
  23.  
  24. #ifndef FWGC_H
  25. #include "FWGC.h"
  26. #endif
  27.  
  28. // ----- Foundation Includes -----
  29.  
  30. #ifndef FWSTREAM_H
  31. #include "FWStream.h"
  32. #endif
  33.  
  34. #ifndef FWEXCLIB_H
  35. #include "FWExcLib.h"
  36. #endif
  37.  
  38. // ----- Macintosh Includes -----
  39.  
  40. #if defined(FW_BUILD_MAC) && !defined(__QUICKDRAW__)
  41. #include <Quickdraw.h>
  42. #endif
  43.  
  44. //========================================================================================
  45. //    RunTime Info
  46. //========================================================================================
  47.  
  48. #if FW_LIB_EXPORT_PRAGMAS
  49. #pragma lib_export on
  50. #endif
  51.  
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment fwgraphx
  54. #endif
  55.  
  56. FW_DEFINE_CLASS_M1(FW_PInk, FW_CGraphicCountedPtr)
  57. FW_DEFINE_CLASS_M1(FW_CInkRep, FW_CGraphicCountedPtrRep)
  58.  
  59. FW_REGISTER_ARCHIVABLE_CLASS(FW_LInkRep, FW_CInkRep, FW_CInkRep::Read, FW_CGraphicCountedPtrRep::Write)
  60.  
  61. //========================================================================================
  62. //    class FW_PInk
  63. //========================================================================================
  64.  
  65. static FW_TransferModes PrivStdInkToTransferMode(FW_EStandardInks std)
  66. {
  67.     switch (std)
  68.     {
  69.     default:
  70.     case FW_kNormalInk:
  71.         return FW_kCopy;
  72.     
  73.     case FW_kNormalTextInk:
  74.         return FW_kOr;
  75.         
  76.     case FW_kInvertInk:
  77.         return FW_kInvert;
  78.         
  79.     case FW_kWhiteEraseInk:
  80.         return FW_kErase;
  81.     }
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //    FW_PInk::FW_PInk
  86. //----------------------------------------------------------------------------------------
  87.  
  88. FW_PInk::FW_PInk() :
  89.     FW_CGraphicCountedPtr()
  90. {
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    FW_PInk::FW_PInk
  95. //----------------------------------------------------------------------------------------
  96.  
  97. FW_PInk::FW_PInk(const FW_CColor& foreColor, const FW_CColor& backColor, FW_TransferModes tranferMode) :
  98.     FW_CGraphicCountedPtr()
  99. {
  100.     SetRep(new FW_CInkRep(foreColor, backColor, tranferMode));
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_PInk::FW_PInk
  105. //----------------------------------------------------------------------------------------
  106.  
  107. FW_PInk::FW_PInk(FW_TransferModes tranferMode) :
  108.     FW_CGraphicCountedPtr()
  109. {
  110.     SetRep(new FW_CInkRep(FW_kRGBBlack, FW_kRGBWhite, tranferMode));
  111. }
  112.  
  113. //----------------------------------------------------------------------------------------
  114. //    FW_PInk::FW_PInk
  115. //----------------------------------------------------------------------------------------
  116.  
  117. FW_PInk::FW_PInk(const FW_PInk& other) :
  118.     FW_CGraphicCountedPtr(other)
  119. {
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    FW_PInk::FW_PInk
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_PInk::~FW_PInk()
  127. {
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    FW_PInk::operator=
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_PInk& FW_PInk::operator=(const FW_PInk& other)
  135. {
  136.     // We don't need to test this == &other because SetRep will do it
  137.     SetRep(other.GetRep());
  138.     return *this;
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. //    FW_PInk::FW_PInk
  143. //----------------------------------------------------------------------------------------
  144.  
  145.  
  146. FW_PInk::FW_PInk(FW_EStandardInks std)
  147. {
  148.     SetRep(new FW_CInkRep(FW_kRGBBlack, FW_kRGBWhite, PrivStdInkToTransferMode(std)));
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    FW_PInk::operator=
  153. //----------------------------------------------------------------------------------------
  154.  
  155. FW_PInk& FW_PInk::operator=(FW_EStandardInks std)
  156. {
  157.     SetRep(new FW_CInkRep(FW_kRGBBlack, FW_kRGBWhite, PrivStdInkToTransferMode(std)));
  158.     return *this;
  159. }
  160.  
  161. //========================================================================================
  162. //    class FW_CInkRep
  163. //========================================================================================
  164.  
  165. //----------------------------------------------------------------------------------------
  166. //    FW_CInkRep::FW_CInkRep
  167. //----------------------------------------------------------------------------------------
  168.  
  169. FW_CInkRep::FW_CInkRep():
  170.     FW_CGraphicCountedPtrRep(),
  171.     fForeColor(FW_kRGBBlack),
  172.     fBackColor(FW_kRGBWhite),
  173.     fTransferMode(FW_kCopy)
  174. {
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. //    FW_CInkRep::FW_CInkRep
  179. //----------------------------------------------------------------------------------------
  180.  
  181. FW_CInkRep::FW_CInkRep(const FW_CColor& foreColor, const FW_CColor& backColor, FW_TransferModes transferMode):
  182.     FW_CGraphicCountedPtrRep(),
  183.     fForeColor(foreColor),
  184.     fBackColor(backColor),
  185.     fTransferMode(transferMode)
  186. {
  187. }
  188.  
  189. //----------------------------------------------------------------------------------------
  190. //    FW_CInkRep::FW_CInkRep
  191. //----------------------------------------------------------------------------------------
  192.  
  193. FW_CInkRep::FW_CInkRep(const FW_CInkRep& otherRep):
  194.     FW_CGraphicCountedPtrRep(),
  195.     fForeColor(otherRep.fForeColor),
  196.     fBackColor(otherRep.fBackColor),
  197.     fTransferMode(otherRep.fTransferMode)
  198. {
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    FW_CInkRep::FW_CInkRep
  203. //----------------------------------------------------------------------------------------
  204.  
  205. FW_CInkRep::FW_CInkRep(FW_CReadableStream& archive) :
  206.     FW_CGraphicCountedPtrRep()
  207. {
  208.     archive >> fForeColor;
  209.     archive >> fBackColor;
  210.     archive >> fTransferMode;
  211. }
  212.  
  213. //----------------------------------------------------------------------------------------
  214. //    FW_CInkRep::~FW_CInkRep
  215. //----------------------------------------------------------------------------------------
  216.  
  217. FW_CInkRep::~FW_CInkRep()
  218. {
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_CInkRep::FW_CInkRep
  223. //----------------------------------------------------------------------------------------
  224.  
  225. FW_CInkRep& FW_CInkRep::operator=(const FW_CInkRep& otherRep)
  226. {
  227.     fForeColor = otherRep.fForeColor;
  228.     fBackColor = otherRep.fBackColor;
  229.     fTransferMode = otherRep.fTransferMode;
  230.     return *this;
  231. }
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    FW_CInkRep::Copy
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_PInk FW_CInkRep::Copy() const
  238. {
  239.     return FW_PInk(fForeColor, fBackColor, fTransferMode);
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. //    FW_CInkRep::IsEqual
  244. //----------------------------------------------------------------------------------------
  245.  
  246. FW_Boolean FW_CInkRep::IsEqual(const FW_CGraphicCountedPtrRep* other) const
  247. {
  248.     if (other == this)
  249.         return TRUE;
  250.         
  251.     FW_CInkRep *inkRep = FW_DYNAMIC_CAST(FW_CInkRep, other);
  252.     if (inkRep)
  253.     {
  254.         return fForeColor == inkRep->fForeColor && 
  255.                 fBackColor == inkRep->fBackColor &&
  256.                 fTransferMode == inkRep->fTransferMode;
  257.     }
  258.     
  259.     return FALSE;
  260. }
  261.  
  262. //----------------------------------------------------------------------------------------
  263. //    FW_CInkRep::Flatten
  264. //----------------------------------------------------------------------------------------
  265.  
  266. void FW_CInkRep::Flatten(FW_CWritableStream& archive) const
  267. {
  268.     archive << fForeColor;
  269.     archive << fBackColor;
  270.     archive << fTransferMode;
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. //    FW_CInkRep::Read
  275. //----------------------------------------------------------------------------------------
  276.  
  277. void* FW_CInkRep::Read(FW_CReadableStream& archive)
  278. {
  279.     FW_CInkRep* objectRep = new FW_CInkRep(archive);
  280.     return objectRep;
  281. }
  282.  
  283.